from datetime import datetime
import tkinter as tk
from gui.config import *
from gui.head_info import *
from sql_handler.handler import handler
from tkinter.ttk import Separator


def normal_page(master, mode, hd, handle=None):
    def return_find():
        mode.set("find")
        handle()

    def return_book():
        mode.set("book")
        handle()

    def return_in():
        mode.set("in")
        handle()

    def return_out():
        mode.set("out")
        handle()

    def return_exit():
        mode.set("exit")
        handle()

    def return_room():
        mode.set("room")
        handle()

    def return_financial():
        mode.set("financial")
        handle()

    bg = '#e0e5df'
    now = datetime.now()
    currDate = f"{now.year}-{now.month}-{now.day}"

    # Separator(master, orient='horizontal', bg='#9ca8b8').pack(fill='x', side='bottom')
    # 宾馆信息
    hotel_info = tk.Frame(master, bg=bg)
    left = 40
    right = 30
    ret = hd.select_left_rooms_count(currDate)
    left_single = 0
    left_double = 0
    left_big = 0
    for item in ret:
        if item[0] == '单人房':
            left_single = item[1]
        elif item[0] == '双人房':
            left_double = item[1]
        else:
            left_big = item[1]

    # 剩余单人间
    lb1 = tk.Label(hotel_info, bg=bg, text='今日剩余单人房： {:d} '.format(left_single), font=myFont)\
        .pack(side='top', anchor='nw', padx=(left, right), pady=(140, 50))

    # 剩余双人间
    lb2 = tk.Label(hotel_info, bg=bg, text='今日剩余双人房： {:d} '.format(left_double), font=myFont) \
        .pack(side='top', anchor='nw', padx=(left, right), pady=(0, 50))

    # 剩余大床房
    lb3 = tk.Label(hotel_info, bg=bg, text='今日剩余大床房： {:d} '.format(left_big), font=myFont) \
        .pack(side='top', anchor='nw', padx=(left, right), pady=(0, 160))

    hotel_info.pack(side='left', fill='y')

    # 操作菜单
    menus = tk.Frame(master, bg=bg)
    left = 20
    right = 30
    bold_font = ('microsoft yahei', 16, 'bold')

    btn1 = tk.Button(menus, text='房间预订', relief='ridge', font=bold_font, width=13, bd=0, fg='white',
                     activebackground='white', bg='#7b8b6f', command=return_book)\
        .pack(side='top', padx=(left, right), pady=(150, 20))
    btn2 = tk.Button(menus, text='预订信息/入住办理', relief='ridge', font=bold_font, width=13, bd=0, fg='white',
                     activebackground='white', bg='#8696a7', command=return_in) \
        .pack(side='top', padx=(left, right), pady=(0, 20))
    btn3 = tk.Button(menus, text='退房办理', relief='ridge', font=bold_font, width=13, bd=0, fg='white',
                     activebackground='white', bg='#a27e7e', command=return_out) \
        .pack(side='top', padx=(left, right), pady=(0, 20))

    menus.pack(side='left', fill='y')

    menus = tk.Frame(master, bg=bg)
    left = 20
    right = 40
    btn0 = tk.Button(menus, text='客户信息查询', relief='ridge', font=bold_font, width=18, bd=0, fg='white',
                     activebackground='white', bg='#7a7281', command=return_find) \
        .pack(side='top', padx=(left, right), pady=(150, 20))
    btn1 = tk.Button(menus, text='房间信息管理', relief='ridge', font=bold_font, width=18, bd=0, fg='white',
                     activebackground='white', bg='#7a7281', command=return_room) \
        .pack(side='top', padx=(left, right), pady=(0, 20))
    btn2 = tk.Button(menus, text='财务报表系统', relief='ridge', font=bold_font, width=18, bd=0, fg='white',
                     activebackground='white', bg='#7a7281', command=return_financial) \
        .pack(side='top', padx=(left, right), pady=(0, 20))
    menus.pack(side='left', fill='y')

    btn4 = tk.Button(menus, text='退出账户', relief='ridge', font=bold_font, width=18, bd=0,
                     activebackground='gray', bg='#f0ebe5', command=return_exit) \
        .pack(side='top', padx=(left, right), pady=(80, 20))


if __name__ == '__main__':
    window = tk.Tk()

    window.geometry('800x600+330+180')
    head_info = tk.Frame(window)
    head_handle(head_info, '19335010')
    head_info.pack(side='top', fill='x')

    page = tk.Frame(window, bg='#e0e5df')
    normal_page(page)
    page.pack(fill='both')
    window.mainloop()

